// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync("logs") || [];
    logs.unshift(Date.now());
    wx.setStorageSync("logs", logs);
  },

  globalData: {
    userInfo: null,
  },

  // 检查登录状态的全局方法
  checkLoginStatus: function () {
    const token = wx.getStorageSync("token");
    const userInfo = wx.getStorageSync("userInfo");
    return {
      isLoggedIn: !!(token && userInfo),
      userInfo: userInfo || null,
    };
  },

  // 跳转至登录页面的全局方法
  navigateToLogin: function (showToast = true) {
    if (showToast) {
      wx.showToast({
        title: "请先登录",
        icon: "none",
        duration: 1500,
      });
    }

    setTimeout(
      () => {
        wx.navigateTo({
          url: "/pages/registration/registration",
        });
      },
      showToast ? 1500 : 0
    );

    return false;
  },
});
